/*
 * Copyright 2009 Prime Technology.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package br.jm.mala.util;

import br.jm.mala.entity.User;
import br.jm.mala.view.UserSession;
import java.io.Serializable;
import java.util.Map;

import javax.faces.context.FacesContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

@Controller
@Scope("session")
public class GuestPreferences implements Serializable {

    private static final long serialVersionUID = 1170285845346711586L;

    private String theme = "blitzer"; //default

    @Autowired
    private UserSession session;

    public String getTheme() {
        Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
        if (params.containsKey("theme")) {
            theme = params.get("theme");
        }
        User user = session.getUser();
        if (user != null) {
            this.theme = user.getTheme();
        }
        return theme;
    }

    public void setTheme(String theme) {
        this.theme = theme;
    }
}
